package com.example.springboot.mapper;


import com.example.springboot.pojo.Department;
import com.example.springboot.pojo.Employee;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//员工Dao
@Repository
@Mapper
public interface EmployeeMapper {

    // 查询
    List<Employee> queryAll();

    Employee queryEmployeeById(@Param("id")int id);


    // 增加
    int addEmployee(Employee employee);

    // 修改
    int updateEmployee(Employee employee);

    // 删除
    int deleteEmployee(@Param("id")int id);





    /*//模拟数据库中的数据
    private static Map<Integer, Employee> employees = null;

    @Autowired
    private DepartmentMapper departmentMapper;
    //想使用departmentDao.getXXXById  但是因为表在static中，优先加载，所以导致不可用
    static {
        employees= new HashMap<Integer,Employee>();

        employees.put(1001,new Employee(1001,"AA","1846846@qq.com",0,new Department(101,"教学部")));
        employees.put(1002,new Employee(1002,"BB","2846846@qq.com",1,new Department(101,"市场部")));
        employees.put(1003,new Employee(1003,"CC","3846846@qq.com",0,new Department(101,"教研部")));
        employees.put(1004,new Employee(1004,"DD","4846846@qq.com",1,new Department(101,"运营部")));
        employees.put(1005,new Employee(1005,"EE","5846846@qq.com",0,new Department(101,"后勤部")));
    }


    //主键自增
    private static Integer initId = 1006;

    //增加一个员工
    public void save(Employee employee){
        if(employee.getId() == null){
            employee.setId(initId++);
        }
        employee.setDepartment(departmentMapper.getDepartmentById(employee.getDepartment().getId()));

        employees.put(employee.getId(),employee);

    }
    //查询全部员工信息
    public Collection<Employee> getAll(){
        return employees.values();
    }

    //通过ID查询员工
    public Employee getEmployeeById(Integer id){
        return employees.get(id);
    }

    //删除员工通过ID
    public void delete(Integer id){
        //调用MAP的remove方法，因为本来就是使用MAP的键值对进行存放，所以增加，删除修改，都直接使用map的方法
        employees.remove(id);
    }
*/
}
